/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GestionDatos;

import java.sql.*;

/**
 *
 * @author yoel
 */
public class Conexion {

    private static Connection con;
    private static Statement stm;
    private static final String URL;
    private static final String USUARIO;
    private static final String CONTRASEÑA;
    private static final String BD;

    static {
        USUARIO = "root";
        CONTRASEÑA = "220812";
        BD = "elviajerobd";
        URL = "jdbc:mysql://localhost:3306/" + BD;
        //CONEXION LOCAL
        /*
        URL = "jdbc:mysql://localhost:3306/pvjavap_db_esc";
        USUARIO = "root";
        CONTRASENIA = "root";
        */
    }
    


    public Statement Conectar() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(URL, USUARIO, CONTRASEÑA);
        return con.createStatement();
    }

    public ResultSet ejecutarSQL(String sql) throws ClassNotFoundException, SQLException {
        return Conectar().executeQuery(sql);
    }

    
    /*public static void ejecutar() throws ClassNotFoundException, SQLException{
        Conectar();
        System.out.println("conectado");
        ResultSet rs = stm.executeQuery("select * from Usuario");
        System.out.println("Ejecutado");
        
        while(rs.next()){
            System.out.println(rs.getString("idUsuario"));
        }
       
    }*/
    
    
   /* public static void ejecutarProcedimiento() throws ClassNotFoundException, SQLException {
        Conectar();
        //stm = con.createStatement();
        CallableStatement cstm = con.prepareCall("{CALL Mostrar(?)}");
        cstm.setString(1, "YoeMartin");
        cstm.registerOutParameter(2, java.sql.Types.VARCHAR);
        cstm.execute();
        //String nombres = cstm.getString("nombres");
        String nombres = cstm.getString(2);
        System.out.println("Los nombres son: " + nombres);
    }*/

    /*public static void ejecutarProc() throws ClassNotFoundException, SQLException {
        Conectar();
        //stm = con.createStatement();
        CallableStatement cstm = con.prepareCall("{CALL Seleccionar()}");
       
        
         cstm.registerOutParameter("idUsuario", java.sql.Types.VARCHAR);
         cstm.registerOutParameter("nombre", java.sql.Types.VARCHAR);
         cstm.registerOutParameter("apellido", java.sql.Types.VARCHAR);
         cstm.registerOutParameter("idDepartamento", java.sql.Types.INTEGER);
         cstm.registerOutParameter("fechaNacimiento", java.sql.Types.DATE);
         cstm.registerOutParameter("contraseña", java.sql.Types.VARCHAR);
         System.out.println("parametros d salida registrados");
        
        cstm.execute();
        System.out.println("ejecutado");

        ResultSet rs = cstm.getResultSet();
       
       while (rs.next()){
            System.out.println(rs.getString("departamento"));
           
       }*/
        
        //String nombres = cstm.getString("nombres");
        
        //ResultSet rs = cstm.getResultSet();
        //System.out.println("ResulSet");
       
        
        
        /*
        String nombre = cstm.getString("nombre").toString();
        System.out.println("nombre");
        
        String apellido = cstm.getString("apellido");
        System.out.println("apellido");
        
        System.out.println("Los nombres son: " + nombre + " " + apellido);
    }*/
}
